import axios from "axios";
axios.defaults.baseURL = "https://autumnfish.cn"

//当用户输入完成 获取对应的歌曲
const reqUsInputComplete = songs => {
    return axios({
        url: "/search",
        params: { keywords: songs }
    }).then(value => {
        const { request } = value
        if (request.status >= 200 && request.status < 300) {
            if (request.readyState === 4) {
                const { songs } = value.data.result
                return songs
            }
        }
        return value
    })
}

//获取 歌曲图片
const reqGetSongImg = songId => {
    return axios({
        url: "/song/detail",
        params: { ids: songId }
    }).then(value => {
        const { request } = value
        if (request.status >= 200 && request.status < 300) {
            if (request.readyState === 4) {
                const { songs } = value.data
                const { picUrl } = songs[0].al
                return picUrl
            }
        }
    })
}

//获取 评论
const reqGetComment = songId => {
    return axios({
        url: "/comment/hot",
        params: { type: 0, id: songId }
    }).then(value => {
        const { request } = value
        if (request.status >= 200 && request.status < 300) {
            if (request.readyState === 4) {
                const { hotComments } = value.data
                return hotComments
            }
        }
    })
}

//获取 音乐mp3
const reqGetMusic = songId => {
    return axios({
        url: "/song/url",
        params: { id: songId }
    }).then(value => {
        const { request } = value
        if (request.status >= 200 && request.status < 300) {
            if (request.readyState === 4) {
                const { data } = value.data
                const { url } = data[0]
                return url
            }
        }
    })
}

export default { reqGetMusic, reqGetComment, reqUsInputComplete, reqGetSongImg }